package com.zfzs.post.modules.merchant.service.impl.mybatis;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zfzs.post.model.dto.QueryMerchantPageListDTO;
import com.zfzs.post.model.vo.QueryAgentPageListVO;
import com.zfzs.post.modules.merchant.domain.Merchant;
import com.zfzs.post.modules.merchant.service.dto.MerchantDTO;
import com.zfzs.post.modules.merchant.service.dto.MerchantQueryCriteria;
import com.zfzs.post.modules.merchant.service.mapper.mybatis.IMerchantMapper;
import com.zfzs.post.modules.merchant.service.mybatis.IMerchantervice;
import com.zfzs.post.page.JpaPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 代理商
 *
 * @author: ck
 * @create: 2019/10/12/11:41
 **/
@Service("iMerchantervice")
public class IMerchantServiceImpl extends ServiceImpl<IMerchantMapper, Merchant> implements IMerchantervice {

    @Autowired
    private IMerchantMapper merchantMapper;

    @Override
    public JpaPageHelper findAgentPageList(QueryMerchantPageListDTO dto) {
        int pageNum = dto.getPageNum();
        int pageSize = dto.getPageSize();
        //借助计算起始位置
        PageRequest pageRequest = PageRequest.of(pageNum, pageSize);
        // 计算数据总条数
        int total = merchantMapper.queryMerchantPageCount(dto);
        List<Map<String,Object>> list = merchantMapper.queryMerchantPageList(dto,pageRequest.getOffset(),pageRequest.getPageSize());
        JpaPageHelper<QueryAgentPageListVO> page = new JpaPageHelper<>(list,pageNum,pageSize,total);
        // 转换分页数据
        page.setResult(list);
        return page;
    }

    @Override
    public String queryMerchantPageSum(QueryMerchantPageListDTO query) {
        return merchantMapper.queryMerchantPageSum(query);
    }

    @Override
    public JpaPageHelper queryMerchantWebPageList(MerchantQueryCriteria dto, Integer pageNum, Integer pageSize) {
        PageRequest pageRequest = PageRequest.of(pageNum, pageSize);//借助计算起始位置
        // 计算数据总条数
        int total = merchantMapper.queryMerchantWebPageCount(dto);
        List<Map<String,Object>> list = merchantMapper.queryMerchantWebPageList(dto,pageRequest.getOffset(),pageRequest.getPageSize());
        JpaPageHelper page = new JpaPageHelper<>(list,pageNum,pageSize,total);
        // 转换分页数据
        page.setResult(list);
        return page;
    }

}
